<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class CI_Controller {

    private static $instance;

    public function __construct() {
        self::$instance = & $this;
        foreach (is_loaded() as $var => $class)
            $this->$var = & load_class($class);
        $this->load = & load_class('Loader', 'core');
        $this->load->initialize();


        $controller = $this->uri->segment(1);
        $controller = (!empty($controller) AND $controller != 'br' AND $controller != 'es' and $controller != 'en') ? $controller : 'default';
        $this->template->set('controller', $controller);
        $this->template->set('text', $this->lang);
        $lang = $this->uri->segment(1);
        session_start();
        if (!empty($lang)) {
            if ($lang == 'br' || $lang == 'es' || $lang == 'en')
                $_SESSION['language'] = $this->uri->segment(1);
        } elseif (!isset($_SESSION['language'])) {
            $_SESSION['language'] = 'br';
        }
        $param2 = $this->uri->segment(2);
        $controller = (!empty($param2)) ?  $this->uri->segment(2) : $controller;
        $this->lang->load($controller, $_SESSION['language']);
        $this->lang->load('meta', $_SESSION['language']);

        log_message('debug', "Controller Class Initialized");
    }

    public static function &get_instance() {
        return self::$instance;
    }

}